package com.zoshine.zzg.pojo.pojostatus;

import com.zoshine.zzg.base.Status;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 商品状态枚举
 *
 * @author 贾俊峰
 * @time 2017/6/20 17:42
 */
public enum GoodsPublicStatus {
    INIT(0, "待申请上架"),
    PUBLISH_FAIL(5, "上架驳回"),
    PUBLISH_AUDIT(9, "上架待审核"),
	PUBLISH(10, "上架"),
//    EDIT_AUDIT(15, "修改待审核"),
//    EDIT_FAIL(20, "修改驳回"),
    DOWN_AUDIT(30,"下架待审核"),
    DOWN_FAIL(50, "下架驳回"),
    DOWN(90,"下架"),
    HISTORY(99, "过期");

    private int value;
    private String desc;
    GoodsPublicStatus(final int value, final String desc) {
        this.value = value;
        this.desc = desc;
    }

    public int getValue() {
        return value;
    }

    public static String getDesc(Integer value) {
        for (GoodsPublicStatus goodsStatus : GoodsPublicStatus.values()) {
            if (Objects.equals(goodsStatus.value, value)) {
                return goodsStatus.desc;
            }
        }
        return null;
    }

    // 缓存一个列表，防止每次使用都进行循环
    private static List<Status> statusList;
    public static List<Status> getList() {
        if (statusList == null || statusList.size() == 0) {
            statusList = new ArrayList<>();
            for (GoodsPublicStatus commonStatus : GoodsPublicStatus.values()) {
                // 将状态存入列表
                Status status = new Status();
                status.setValue(commonStatus.value);
                status.setDesc(commonStatus.desc);
                statusList.add(status);
            }
        }
        return statusList;
    }
}
